package com.sf;

public class LinkList {
    private  Node head;
    private  Node tail;

    public LinkList() {
        head = null;
        tail = null;
    }
    public void add(int data) {
        Node node = new Node(data);
        if (head == null) {
            head = node;
        } else {
            tail.next = node;
        }
        tail = node;
    }

    public void printAll() {
        Node node = head;
        while (node != null) {
            System.out.print(node.data + " ");
            node = node.next;
        }
        System.out.println();
    }

    public void del(int data) {
        Node node = head;
        while (node != null) {
            if (node.next.data == data) {
                node.next = node.next.next;
            } else {
                node = node.next;
            }
        }
    }

    public int pop() {
        int data = head.data;
        if (head.next != tail) {
            head = head.next;
        }
        return data;
    }
}
